package com.ude.pim.controller;

import com.ude.pim.common.R;
import com.ude.pim.dto.CaseSubDTO;
import com.ude.pim.dto.CaseSubQueryDTO;
import com.ude.pim.entity.CaseSub;
import com.ude.pim.service.CaseSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yb
 * @since 2023-08-08
 */
@RestController
@RequestMapping("/caseSub")
public class CaseSubController {
    @Autowired
    private CaseSubService caseSubService;

    @PostMapping
    public R<String> save(@RequestBody CaseSub caseSub){
        caseSubService.save(caseSub);
        return R.success("新增成功");
    }

    @PutMapping
    public R<String> update(@RequestBody CaseSub caseSub){
        caseSubService.updateById(caseSub);
        return R.success("修改成功");
    }

    @GetMapping("/page")
    public R<List<CaseSub>> page(@RequestBody CaseSubQueryDTO caseSubQueryDTO){
        return caseSubService.page(caseSubQueryDTO);
    }

    /**
     * 传入负责人id，返回其负责的子流程DTO集合
     * @param chargeId
     * @return
     */
    @GetMapping("/director/{chargeId}")
    public R<List<CaseSubDTO>> getByChargeId(@PathVariable("chargeId") Long chargeId){
        return caseSubService.getByChargeId(chargeId);
    }

    @GetMapping("/list")
    public R<List<CaseSubDTO>> list(){
        return caseSubService.getList();
    }

    @GetMapping("/list/{caseId}")
    public R<List<CaseSubDTO>> getByCaseId(@PathVariable("caseId") Long caseId){
        return caseSubService.getByCaseId(caseId);
    }
}
